import SlideView from '@/components/SlideView/SlideView'

export default {
  components: {
    SlideView
  },
  props: {
    id: {
      type: [String, Number],
      default: ''
    }
  },
  data() {
    return {
      api: null,
      detail: {},
      editVisible: false,
      loading: false,
      zIndex: this.$common.getMaxIndex()
    }
  },
  watch: {
    id: function() {
      this.getDetail()
    }
  },
  mounted() {},
  methods: {
    setApi(api) {
      this.api = api
    },
    getDetail() {
      this.loading = true
      this.api.get(this.id).then(res => {
        this.detail = res.data
      }).finally(() => {
        this.loading = false
      })
    },
    handleEdit() {
      this.editVisible = true
    },
    handleCallback(data) {
      if (data.type === 'edit') {
        this.editVisible = true
      } else if (data.type === 'delete') {
        this.handleClose()
      }
      this.$emit('callback', data)
    },
    handleClose() {
      this.$emit('close')
    }
  }
}
